package com.mentaleye.controller;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.bean.GroupBean;
import com.mentaleye.biz.DictionaryBiz;
import com.mentaleye.biz.GroupBiz;
import com.mentaleye.enums.DictionaryEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * Created by Rock on 2017/5/9.
 */
@Controller
@RequestMapping("/group")
public class GroupController {

    @Autowired private GroupBiz groupBiz;
    @Autowired private DictionaryBiz dictionaryBiz;

    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView view = new ModelAndView("ea/group/groupIndex");
        Map<Integer, String> personRoles = dictionaryBiz.queryDictionaryByParent(DictionaryEnums.GROUP_PERSON_ROLE.getCode());
        view.addObject("personRolesMap",personRoles);
        view.addObject("personRoles",JSONObject.toJSONString(personRoles));
        return view;
    }

    @RequestMapping("/treeData")
    @ResponseBody
    public String loadTree(){
        return JSONObject.toJSONString(groupBiz.queryByList(DictionaryEnums.STUDENT_GROUP.getCode()));
    }

    @RequestMapping("/edit")
    @ResponseBody
    public String edit(GroupBean bean){
        return JSONObject.toJSONString(groupBiz.edit(bean));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public String remove(@RequestParam(value = "id")Integer groupId){
        return JSONObject.toJSONString(groupBiz.remove(groupId));
    }
}
